import { useEffect } from 'react'
import { message } from 'antd'
import { api } from './services/api'
import AppRouter from './router'

function App() {
  // 初始化时测试Mock API
  useEffect(() => {
    const testMockApi = async () => {
      try {
        console.log('开始测试Mock API - 准备发送请求到 /api/users');
        const data = await api.get('/users', { page: 1, pageSize: 5 });
        console.log('Mock API 测试结果:', data);
        message.success('Mock API 测试成功！');
      } catch (error) {
        console.error('Mock API 测试失败:', error);
        message.error('Mock API 测试失败！');
        
        // 尝试使用fetch API直接请求，用于调试
        try {
          const response = await fetch('/api/users?page=1&pageSize=5');
          const text = await response.text();
          console.log('Fetch API 响应:', text);
        } catch (fetchError) {
          console.error('Fetch API 测试也失败:', fetchError);
        }
      }
    };
    
    testMockApi();
  }, []);

  return <AppRouter />
}

export default App